import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'costMaintainM',
  state: {
    allDictByKey: {},
  },
  effects: {
    //新增费用
    *addCost({ payload, callback }, { call, put, select }) {
      const res = yield call(api.costMaintain.addCost, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
    //删除费用
    *deleteCost({ payload, callback }, { call, put, select }) {
      const res = yield call(api.costMaintain.deleteCost, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
    //编辑费用
    *editCost({ payload, callback }, { call, put, select }) {
      const res = yield call(api.costMaintain.editCost, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
    //查询费用列表
    *findAllCost({ payload, callback }, { call, put, select }) {
      const res = yield call(api.costMaintain.findAllCost, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
